/*
 * @description:
 * @version:
 * @Author: 王治飞
 * @Date: 2023-08-17 10:06:27
 * @LastEditors: 王治飞
 * @LastEditTime: 2023-08-17 10:25:53
 */
import axios from 'axios'

import { BASE_URL, TIMEOUT } from './config.js'

class Request {
  constructor(baseURL, timeout) {
    this.instance = axios.create({
      baseURL,
      timeout
    })

    this.instance.interceptors.response.use(
      res => {
        return res.data
      },
      err => {
        return err
      }
    )
  }

  request(consfig) {
    return this.instance.request(consfig)
  }

  get(config) {
    return this.request({ ...config, method: 'get' })
  }

  post(config) {
    return this.request({ ...config, method: 'post' })
  }
}

const request = new Request(BASE_URL, TIMEOUT)
export default request
